package com.nc.user.controller;


import com.nc.user.model.dto.PermissionsDto;
import com.nc.user.service.PermissionsService;
import com.plug.result.RetResponse;
import com.plug.result.RetResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
@RestController
@RequestMapping("PermissionsController")
@Api(tags = "权限接口")
public class PermissionsController {
    @Autowired
    private PermissionsService permissionsService;


    @ApiOperation("新增权限")
    @PostMapping("permissions")
    public RetResult addPermissions(@RequestBody PermissionsDto permissionsDto) {
        return permissionsService.addPermissions(permissionsDto);
    }

    @ApiOperation("根据id删除权限")
    @DeleteMapping("permissions/{id}")
    public RetResult deletedById(@PathVariable String id) {
        return permissionsService.deleteById(id);
    }

    @ApiOperation("查询所有权限")
    @GetMapping("permissions")
    public RetResult findAll() {
        return permissionsService.findAll();
    }

    @ApiOperation("根据role查询权限")
    @PostMapping("role/permissions")
    public RetResult findByRole(@RequestBody List<String> roles) {
        return RetResponse.makeOKRsp(permissionsService.findByRoles(roles));
    }
}
